import { baseRequestClient } from './request';

export interface CaptchaResult {
  captchaImage: string;
  captchaKey: string;
}

/** 登录入参 */
export interface LoginInParams {
  captchaCode: string;
  captchaKey: string;
  password: string;
  username: string;
}

/**
 * @description 获取验证码（返回 base64 图片和 key）
 */
export async function getCaptcha(): Promise<CaptchaResult> {
  const res = await baseRequestClient.get('/captcha');
  // 后端结构：{ code: 200, data: { captchaImage, captchaKey } }
  return (res?.data?.data ?? { captchaImage: '', captchaKey: '' }) as CaptchaResult;
}

/**
 * @description 登录接口（携带验证码参数），POST /login
 */
export async function LoginIn(payload: LoginInParams) {
  const res = await baseRequestClient.post('/login', payload);
  return res?.data?.data;
}
